package pl.edu.pk.mech.kkbus.component;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import pl.edu.pk.mech.kkbus.service.UserService;
import pl.edu.pk.mech.kkbus.service.AwardService;
import pl.edu.pk.mech.kkbus.service.NewService;
import pl.edu.pk.mech.kkbus.service.DefectService;
import pl.edu.pk.mech.kkbus.service.BussesService;

import pl.edu.pk.mech.kkbus.model.User;
import pl.edu.pk.mech.kkbus.model.Award;
import pl.edu.pk.mech.kkbus.model.New;
import pl.edu.pk.mech.kkbus.model.Defect;
import pl.edu.pk.mech.kkbus.model.Bus;

@Component
public class DataLoader { 
    
    private static final Logger log = Logger.getLogger(DataLoader.class.getName());
    
    @Autowired
    UserService userService;
    
    @Autowired
    AwardService awardServices;
    
    @Autowired
    NewService newService;
    
    @Autowired
    DefectService defectService;
    
    @Autowired
    BussesService bussesService;
    
    @PostConstruct
    public void init() {
        
        // Init data ? true/false
        if (true) { 
            log.info("Load example data...");
            
            // user
            Set<User.Role> authorities = new HashSet<User.Role>();
            authorities.add(User.Role.USER);            
            User user = new User();
            user.setAuthorities(authorities);            
            user.setBirthday(new Date());
            user.setEmail("kuciu19@wp.pl");
            user.setEnabled(true);
            user.setName("Jan");
            user.setPassword("qwerty123");
            user.setPhone("999888777");
            user.setPoints(10000);
            user.setSurname("Kowalski");
            // save
            userService.createUser(user);
            
            // worker
            authorities = new HashSet<User.Role>();
            authorities.add(User.Role.WORKER);            
            user = new User();
            user.setAuthorities(authorities);            
            user.setBirthday(new Date());
            user.setEmail("workerr@kkbus.pl");
            user.setEnabled(true);
            user.setName("Andrzejj");
            user.setPassword("qwerty1234");
            user.setPhone("888999776");
            user.setPoints(20002);
            user.setSurname("Nowakk");
            userService.createUser(user);
            
            authorities = new HashSet<User.Role>();
            authorities.add(User.Role.WORKER);            
            user = new User();
            user.setAuthorities(authorities);            
            user.setBirthday(new Date());
            user.setEmail("worker@kkbus.pl");
            user.setEnabled(true);
            user.setName("Andrzej");
            user.setPassword("qwerty123");
            user.setPhone("888999777");
            user.setPoints(20000);
            user.setSurname("Nowak");
            //save
            userService.createUser(user);
            
            // admin
            authorities = new HashSet<User.Role>();
            authorities.add(User.Role.ADMIN);
            user = new User();
            user.setAuthorities(authorities);            
            user.setBirthday(new Date());
            user.setEmail("admin@kkbus.pl");
            user.setEnabled(true);
            user.setName("Paweł");
            user.setPassword("qwerty123");
            user.setPhone("777888999");
            user.setPoints(50000);
            user.setSurname("Grzybczyk");
            // save
            userService.createUser(user);
            
//            // awards
//            awardServices.createOrUpdateAward(new Award("Kubek", "<img src='http://pl.lipsum.com/images/lipsum07.gif' alt=''>", 100, 19));
//            awardServices.createOrUpdateAward(new Award("Samochodzik", "<img src='http://images.okazje.info.pl/p/inne/1837/th100/hot-wheels-ferrari-fxx-23.jpg' alt=''>", 150, 20));
//            awardServices.createOrUpdateAward(new Award("Parasol", "<img src='http://www.kompas.pl/lop/img/super_parasol.jpg' alt=''>", 250, 5));
//            awardServices.createOrUpdateAward(new Award("Termos", "<img src='http://i91.twenga.com/sport/termos/termos-kod-mcm-6542005-tp_5494982512297994200.jpg' alt=''>", 500, 19));
//            awardServices.createOrUpdateAward(new Award("Latarka Energizer", "<img src='http://www.ramtech.pl/img/uploaded_images/mini/black_eye_mx132l.jpg' alt=''>", 1250, 20));
//            awardServices.createOrUpdateAward(new Award("Zestaw narzędzi", "<img src='http://cdn13.epasaz.smcloud.net/t/files/thumbnails/1dc7e96230911915_100x100_rozmiar-niestandardowy.jpg' alt=''>", 3000, 5));
//            awardServices.createOrUpdateAward(new Award("Plecak sportowy", "<img src='http://i90.twenga.com/informatyka/plecak-na-laptopa/plecak-sportowy-adidas-performance-tp_8296025043934318459.jpg' alt=''>", 3375, 19));
//            awardServices.createOrUpdateAward(new Award("Suszarka do włosów", "<img src='http://sklep.chip.pl/product_picture/4/AMSUPHILHP496200/Suszarka_Philips_HP_4962/22-d275b04e.png' alt=''>", 3600, 20));
//            awardServices.createOrUpdateAward(new Award("Waga łazienkowa", "<img src='http://i91.twenga.com/zdrowie-i-uroda/waga-lazienkowa/soehnle-waga-lazienkowa-exacta-tp_221297351175847768.jpg' alt=''>", 3880, 5));
//            
//            // news
//            newService.addNews(new New("Zmiana przystanku", "Od dnia 01.03.2013 r. następuje zmiana miejsca odjazdu autokarów z Katowic do Krakowa. Przystanek zostaje przeniesiony na przeciwną stronę ulicy od Dw. PKP", new Date()));
//            newService.addNews(new New("Nowości", "Dla poprawy komfortu podróży wprowadzony zostanie nowy rozkład jazdy o 30% więcej kursów", new Date()));
//            newService.addNews(new New("Zmiana przystanku", "Niestety mamy smutną wiadomość dla naszych klientów. Dnia 14.04.2013 wszystkie kursy na trasie Katowice-Kraków muszą zostać odwołane. Za utrudnienia przepraszamy", new Date()));
//            newService.addNews(new New("Dodatkowe informacje", "Informacja telefoniczna o kursach krajowych pod numerem 0 703 40 33 40", new Date()));
//            
//            // busses
//            bussesService.createOrUpdateBusses(new Bus(1l, "Mercedes", "Lorem ipsum.", 12, new Date(), "KOS2311", ""));
//            bussesService.createOrUpdateBusses(new Bus(11, "Gazela", "Lorem ipsum.", 12, new Date(), "KRKR111", ""));
//            bussesService.createOrUpdateBusses(new Bus(11, "Jelcz", "Lorem ipsum.", 12, new Date(), "KWI1212", ""));
            
            // defects
//            defectService.createOrUpdateDefect(new Defect(1l, "Uszczelka pod głowicą", new Date(), 599.87, "1"));
//            defectService.createOrUpdateDefect(new Defect(2l, "Rozbita lewa lampa", new Date(), 289.00, "1"));
        }        
    }
}
